package com.dure.commonlib.util;

import android.content.Context;
import android.content.res.AssetManager;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;

/**
 * Created by leix on 8/16/16.
 */
public class AssetsUtil {
    public static InputStream getAssets(Context context, String fileName) {
        AssetManager assetManager = context.getAssets();

        try {
            InputStream is = assetManager.open(fileName);

            return is;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static ArrayList<String> getAssetsList(Context context, String dirName) {
        ArrayList<String> fileList = new ArrayList<>();
        AssetManager assetManager = context.getAssets();
        try {
            String[] fileArr = assetManager.list(dirName);
            Collections.addAll(fileList, fileArr);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return fileList;
    }


}
